#!/bin/bash

cd `dirname $0`

# 使用mvn命令很慢
#jar_file=$(mvn -q \
#    -Dexec.executable=echo \
#    -Dexec.args='${project.artifactId}-${project.version}.jar' \
#    --non-recursive \
#    exec:exec)
artifactId=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='artifactId']/text()" pom.xml)
version=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" pom.xml)
jar_file=$artifactId-$version.jar
mem_sz=300m # 250 ~ 4G

if [ "$1" == "1" ]; then
    mvn clean package -U -Dmaven.test.skip=true
fi

rm -f nohup.out &>/dev/null
nohup \
java \
    -Xmx$mem_sz -Xms$mem_sz \
    -Djava.security.egd=file:/dev/./urandom \
    -Duser.timezone=Asia/Shanghai \
    -jar "$PWD/target/$jar_file" \
        --spring.profiles.active=prod \
&

sleep 3 # wait nohup.out created
tail -f nohup.out